package com.map;

import android.content.Context;
import android.graphics.Point;
import android.util.AttributeSet;
import com.mapbar.map.MapRenderer;
import com.mapbar.map.MapView;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

public class RnMapViewWrapper extends MapView {
    private boolean mInited = false;
    private MapRenderer mRenderer = null;
    private Point worldCenterPoint = null;
    private float zoomLevel = -1;
    public RnMapViewWrapper(Context context) {
        super(context);
    }
    public RnMapViewWrapper(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
    }

    @Override
    public void onSurfaceCreated(GL10 gl10, EGLConfig eglConfig) {
        super.onSurfaceCreated(gl10, eglConfig);
        // 防止重复创建
        if (!mInited) {
            mRenderer = super.getMapRenderer();
            if (mRenderer == null)
                return;
            mInited = true;
            if(this.zoomLevel > -1) {
                this.setZoomLevel(this.zoomLevel);
            }
            if(this.worldCenterPoint != null) {
                this.setWorldCenter(this.worldCenterPoint);
            }
        }
    }

    public void setZoomLevel(float zoomLevel) {
        this.zoomLevel = zoomLevel;
        if (mInited && mRenderer != null) {
            mRenderer.setZoomLevel(zoomLevel);
        }
    }

    public void setWorldCenter(Point worldCenterPoint) {
        this.worldCenterPoint = worldCenterPoint;
        if (mInited && mRenderer != null) {
            mRenderer.setWorldCenter(worldCenterPoint);
        }
    }
}
